<template>
  <div>
    <h1>Pipeline Edit</h1>

    <el-form label-width="150px">
      <el-form-item label="description">
        <el-input v-model="pipeline.description"></el-input>
      </el-form-item>
      <el-form-item label="eventFilter">
        <el-input v-model="pipeline.eventFilter"></el-input>
      </el-form-item>
      <el-form-item label="sourceDataNodeId">
        <el-input v-model="pipeline.sourceDataNodeId"></el-input>
      </el-form-item>
      <el-form-item label="sourceSchema">
        <el-input v-model="pipeline.sourceSchema"></el-input>
      </el-form-item>
      <el-form-item label="sourceTable">
        <el-input v-model="pipeline.sourceTable"></el-input>
      </el-form-item>
      <el-form-item label="targetDataNodeId">
        <el-input v-model="pipeline.targetDataNodeId"></el-input>
      </el-form-item>
      <el-form-item label="targetSchema">
        <el-input v-model="pipeline.targetSchema"></el-input>
      </el-form-item>
      <el-form-item label="targetTable">
        <el-input v-model="pipeline.targetTable"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="$router.go(-1)">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Message } from 'element-ui';

export default {
  data() {
    return {
      pipeline: {}
    }
  },

  methods: {
    loadById() {
      if (!this.$route.query.id) {
        return;
      }

      var _this = this;
      sdk.PipelineApi().findById({
        id: _this.$route.query.id
      }).then(res => {
        _this.pipeline = res;
      });
    },

    onSubmit() {
      if (!!this.$route.query.id) {
        this.updateIgnoreNull();
        return;
      }

      this.insertIgnoreNull();
    },

    insertIgnoreNull() {
      var _this = this;
      sdk.PipelineApi().insertIgnoreNull({
        pipeline: _this.pipeline
      }).then(res => {
        console.log('#74 insertIgnoreNull', res);
        Message('添加成功');
      });
    },

    updateIgnoreNull() {
      var _this = this;
      sdk.PipelineApi().updateIgnoreNull({
        pipeline: _this.pipeline
      }).then(res => {
        console.log('#84 updateIgnoreNull', res);
        Message('更新成功');
      });
    }
  },

  mounted(){
    this.loadById();
  }
};
</script>

<style>
</style>